package com.lvmama.dashboard.core.ssh;

import java.io.Serializable;
import java.util.Map;

import org.springframework.web.context.ContextLoaderListener;

import com.lvmama.rhino.utils.JedisClusterUtils;

public class RmtShellRunner implements Runnable, Serializable {
	private static final long serialVersionUID = 9139589321227253092L;
	private String uuid;
	private String shellName;
	private Map<String, String> param;
	
	public RmtShellRunner(String uuid, String shellName, Map<String, String> param) {
		this.uuid = uuid;
		this.shellName = shellName;
		this.param = param;
	}
	
	@Override
	public void run() {
		Map<String, Object> shellQueue = JedisClusterUtils.getInstance().hmget("shell_queue");
		shellQueue.remove(uuid);
		JedisClusterUtils.getInstance().hmset("shell_queue", shellQueue);
		ServerShellHelper serverShellHelper = ContextLoaderListener.getCurrentWebApplicationContext().getBean(ServerShellHelper.class);
		serverShellHelper.exec(shellName, param);
	}

	public String getShellName() {
		return shellName;
	}
}
